/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using DOAN.DO;
/// <summary>
/// Summary description for MonhocDAL
/// </summary>
namespace DOAN.DAL
{

    public class MonhocDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public MonhocDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(MonhocDO objMonhocDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMonhoc_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Mamonhoc", SqlDbType.VarChar);
            Sqlparam.Value = objMonhocDO.Mamonhoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tenmon", SqlDbType.NVarChar);
            Sqlparam.Value = objMonhocDO.Tenmon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Sochuong", SqlDbType.VarChar);
            Sqlparam.Value = objMonhocDO.Sochuong;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(MonhocDO objMonhocDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMonhoc_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Mamonhoc", SqlDbType.VarChar);
            Sqlparam.Value = objMonhocDO.Mamonhoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tenmon", SqlDbType.NVarChar);
            Sqlparam.Value = objMonhocDO.Tenmon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Sochuong", SqlDbType.VarChar);
            Sqlparam.Value = objMonhocDO.Sochuong;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(MonhocDO objMonhocDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMonhoc_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Mamonhoc", SqlDbType.VarChar);
            Sqlparam.Value = objMonhocDO.Mamonhoc;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMonhoc_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public MonhocDO Select(MonhocDO objMonhocDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMonhoc_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Mamonhoc", SqlDbType.VarChar);
            Sqlparam.Value = objMonhocDO.Mamonhoc;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["Mamonhoc"]))
                    objMonhocDO.Mamonhoc = Convert.ToString(dr["Mamonhoc"]);
                if (!Convert.IsDBNull(dr["Tenmon"]))
                    objMonhocDO.Tenmon = Convert.ToString(dr["Tenmon"]);
                if (!Convert.IsDBNull(dr["Sochuong"]))
                    objMonhocDO.Sochuong = Convert.ToString(dr["Sochuong"]);

            }
            return objMonhocDO;
        }

        public DataTable TimKiem(int tt,string tk)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "[spMonhoc_Timkiem]";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@tt", SqlDbType.VarChar);
            Sqlparam.Value = tt;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tenmon", SqlDbType.VarChar);
            Sqlparam.Value = tk;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = new DataTable();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dt = ds.Tables[0];
            }
            return dt;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMonhoc_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrMonhocDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    MonhocDO objMonhocDO = new MonhocDO();
                    if (!Convert.IsDBNull(dr["Mamonhoc"]))
                        objMonhocDO.Mamonhoc = Convert.ToString(dr["Mamonhoc"]);
                    if (!Convert.IsDBNull(dr["Tenmon"]))
                        objMonhocDO.Tenmon = Convert.ToString(dr["Tenmon"]);
                    if (!Convert.IsDBNull(dr["Sochuong"]))
                        objMonhocDO.Sochuong = Convert.ToString(dr["Sochuong"]);
                    arrMonhocDO.Add(objMonhocDO);
                }
            }
            return arrMonhocDO;
        }

        public DataTable SelectAllDistiny()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMonHoc_SelectAllDistiny";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMonhoc_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public object GetSoChuong(string mon)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMonhoc_GetChuong";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Mamonhoc", SqlDbType.VarChar);
            Sqlparam.Value = mon;
            Sqlcomm.Parameters.Add(Sqlparam);

            object obj = base.ExecuteScalar(Sqlcomm);
            return obj;
        }
        #endregion

    }

}
